package com.example.lyl.testpermission;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Toast;

import kr.co.namee.permissiongen.PermissionFail;
import kr.co.namee.permissiongen.PermissionGen;
import kr.co.namee.permissiongen.PermissionSuccess;

@SuppressWarnings("MissingPermission")
public class MainActivity extends Activity implements View.OnClickListener {

    private Button callPhone, downLoad;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        callPhone = (Button) findViewById(R.id.callPhone);
        downLoad = (Button) findViewById(R.id.download);
        callPhone.setOnClickListener(this);
        downLoad.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.callPhone:
                playcallPhone();
                break;
            case R.id.download:
                playDownLoad();
                break;
            default:
                break;
        }
    }

    private void playcallPhone() {
        PermissionGen.needPermission(MainActivity.this, 100,
                new String[] {

                        Manifest.permission.CAMERA
                }
        );

    }

    @PermissionSuccess(requestCode = 100)
    public void doSomething(){
        Toast.makeText(this, "Contact permission is granted", Toast.LENGTH_SHORT).show();
    }

    @PermissionFail(requestCode = 100)
    public void doFailSomething(){
        Toast.makeText(this, "Contact permission is not granted", Toast.LENGTH_SHORT).show();
    }

    private void playDownLoad() {

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        PermissionGen.onRequestPermissionsResult( this,requestCode,  permissions, grantResults);
    }
}
